import { fileURLToPath, URL } from 'node:url'
import path from 'path'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueDevTools(),
  ],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src')
    },
  },
  server: {
    port: 3000,
    proxy: {
      '/api': {
        target: 'http://localhost:8082',
        changeOrigin: true,
        ws: true,
        secure: false,
        configure: (proxy, options) => {
          proxy.on('error', (err, req, res) => {
            console.log('proxy error', err);
          });
          proxy.on('proxyReq', (proxyReq, req, res) => {
            console.log('Sending Request:', req.method, req.url);
          });
          proxy.on('proxyRes', (proxyRes, req, res) => {
            console.log('Received Response:', proxyRes.statusCode, req.url);
          });
        }
      },
      '/upload': {
        target: 'http://localhost:8082',
        changeOrigin: true,
        ws: true,
        secure: false
      },
      '/admin': {
        target: 'http://localhost:8082',
        changeOrigin: true,
        ws: true,
        secure: false
      },
      '/dashboard': {
        target: 'http://localhost:8082',
        changeOrigin: true,
        ws: true,
        secure: false
      },
      '/course': {
        target: 'http://localhost:8082',
        changeOrigin: true,
        ws: true,
        secure: false
      },
      '/users': {
        target: 'http://localhost:8082',
        changeOrigin: true,
        ws: true,
        secure: false
      },
      '/category': {
        target: 'http://localhost:8082',
        changeOrigin: true,
        ws: true,
        secure: false
      },
      '/subject': {
        target: 'http://localhost:8082',
        changeOrigin: true,
        ws: true,
        secure: false
      },
      '/teacher': {
        target: 'http://localhost:8082',
        changeOrigin: true,
        ws: true,
        secure: false
      }
    },
    open: true
  }
})
